package com.tql.kingdee.util;

import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class CommonUtil {
    /**
     * redis相关的静态常量配置
     */
    public final static String RK_LoginSessionid = "RK_LoginSessionid";
    public final static Long RK_LoginSessionid_timeout = 7200L;
    public final static int OrgType_COMPANY = 0;
    public final static int OrgType_COMPANY_DEPT = 1;

    public final static String TABLENAME_TQL_MATARIAL_PURCHASE = "tql_material_purchase";
    public final static String TABLENAME_TQL_MATARIAL_INCASE = "tql_material_incase";
    public final static String TABLENAME_TQL_KINGDEE_TRANSFER = "tql_kingdee_transfer";

    public final static String TQL_STAP_IN_CHANGE = "tql_stap_in_change";


    public static String getStringDepts(List<String> depts) {
        if (CollectionUtils.isEmpty(depts)) return "";
        //   String result = String.join(",", depts);
        String result = "'" + String.join("','", depts) + "'";
        return result;
    }

    public static String getStringDepts1(List<String> depts) {


        if (CollectionUtils.isEmpty(depts)) return "";

        List<String> list = depts.stream()
                .map(dept -> dept + "000")
                .collect(Collectors.toList());
       return getStringDepts(list);
}











    // 替换前缀并拼接数字部分
    public static String deptCodeReplacePrefix(String originalString) {
        String prefix = "BU"; // 新的前缀
        // 使用正则表达式匹配首次出现的数字位置及其之前的字符
        String[] parts = originalString.split("(?<=\\D)(?=\\d)");
        // 构建新字符串
        String str = prefix + parts[1];
        if (str.length() >= 18) {
            // 获取字符串长度
            int len = str.length();
            // 使用 substring 方法截取从头开始到倒数第三位之前的子字符串
            str = str.substring(0, len - 3) + str.substring(len - 2);
        }
        return str;
    }

}
